/**
 * @author Wang Hai Long  [whailong2010@gmail.com]
 * @date Sep 27, 2014 5:18:26 PM
 */
package com.surent.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Wang Hai Long [whailong2010@gmail.com]
 * @date Sep 27, 2014 5:18:26 PM
 */
public class SignUpValidator implements Validator {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.surent.utils.Validator#getResult()
	 */
	private String phoneNum;
	private String password;
	private String confirmPw;

	/**
	 * @param phoneNum
	 * @param password
	 * @param confirmPw
	 */
	public SignUpValidator(String phoneNum, String password, String confirmPw) {
		this.phoneNum = phoneNum;
		this.password = password;
		this.confirmPw = confirmPw;
	}

	@Override
	public String getResult() {
		if ("".equals(phoneNum)) {
			return "请输入手机号";
		}
		Pattern p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号
		Matcher m = p.matcher(phoneNum);
		if (!m.matches()) {
			return "手机号格式不正确";
		}

		if ("".equals(password)) {
			return "请输入登录密码";
		}
		
		if (password.length() < 4) {
			return "密码长度需要4位以上";
		}

		if ("".equals(confirmPw)) {
			return "请输入确认密码";
		}

		if (!password.equals(confirmPw)) {
			return "两次输入的密码不一致";
		}

		return null;
	}

}
